package cz.gelion.shylock.invoice.entity

import javax.persistence.Entity
import javax.persistence.Table
import scala.beans.BeanProperty
import javax.persistence.Column
import java.util.Calendar
import javax.persistence.Temporal
import javax.persistence.TemporalType
import javax.persistence.Id
import javax.persistence.GeneratedValue
import cz.gelion.shylock.invoice.ManagedInfo
import javax.persistence.PreUpdate
import javax.persistence.PrePersist
import javax.persistence.ManyToOne
import javax.persistence.JoinColumn
import java.io.Serializable

@Entity
@Table(name="manager")
class Manager(s:String) extends Equals with ManagedInfo with Serializable {

  def this() = this(null)
  
  @Id
  @BeanProperty
  @Column(name="id")
  var id:String = s
  
  @BeanProperty
  @ManyToOne
  @JoinColumn(name="muser")
  var manager:Manager = _
  
  
  @BeanProperty
  @Column(name="mtime")
  @Temporal(TemporalType.TIMESTAMP)
  var mtime:Calendar = _
  
  @PreUpdate
  @PrePersist
  def upate = stamp
  
  def canEqual(that:Any):Boolean = that.isInstanceOf[Manager]
  
  override def equals(that:Any):Boolean = {
    that match {
      case o:Manager => o.canEqual(this) && id != null && id == o.id
      case _ => false 
    }   
  } 
  
  override def hashCode:Int = 13 + (if (id==null) 0 else id.hashCode)
}